﻿
#region 引用
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using SiteCommon;
using BLL;

using Model;
#endregion

public partial class CustomerManage_QuestionManage : System.Web.UI.Page
{
    #region 字段
    private string _callPhone = "";
    private int _callRecordId = 0;
    #endregion

    #region 页面初始化程序
    /// <summary>
    /// 页面初始化程序
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        this._callPhone = SiteCommon.Common.GetString(Request.QueryString["CallPhone"]);
        this._callRecordId = SiteCommon.Common.GetInt(Request.QueryString["CallRecordId"]);


        lblError.Text = "";

        if (!this.IsPostBack)
        {
            this.GetPagingQuestionList();
        }

    }
    #endregion

    #region 获取当前页客户问答列表
    /// <summary>
    /// 获取当前页客户问答列表
    /// </summary>
    private void GetPagingQuestionList()
    {
        List<Model.RECORDQUESTION> list;
        int recordCount = 0;

        RecordQuestionBL mInter = new RecordQuestionBL();
        string ret = mInter.GetQuestionList(CutPageBar1.PageIndex,
            CutPageBar1.PageSize,
            this._callPhone,
            out list,
            out recordCount);

        CutPageBar1.RecordCount = recordCount;

        if (ret == Model.Config.SUCCESS)
        {
            rpList.Visible = true;
            rpList.DataSource = list;
            rpList.DataBind();
        }
        else
        {
            rpList.Visible = false;
            lblError.Text = ret;
        }        
    }
    #endregion

    #region 添加客户问答
    /// <summary>
    /// 添加客户问答
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (this._callRecordId == 0)
        {
            lblError.Text = "请先添加客户来电记录";
            return;
        }

        Model.RECORDQUESTION model = new Model.RECORDQUESTION();
        model.CallRecordId = this._callRecordId;
        model.Question = txtQuestion.Text.Trim();
        model.Answer = txtAnswer.Text.Trim();

        RecordQuestionBL mInter = new RecordQuestionBL();
        string ret = mInter.Add(model);

        if (ret == Model.Config.SUCCESS)
        {
            this.GetPagingQuestionList();
            btnClear_Click(sender, e);
        }
        else
        {
            lblError.Text = ret;
        }
    }
    #endregion

    #region 清空数据
    /// <summary>
    /// 清空数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnClear_Click(object sender, EventArgs e)
    {
        txtAnswer.Text = "";
        txtQuestion.Text = "";
    }
    #endregion

    #region 分页
    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void CutPage(object sender, SiteCommon.ChangePageArgs e)
    {
        CutPageBar1.PageIndex = e.PageIndex;
        this.GetPagingQuestionList();
    }
    #endregion
}
